package manager.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/pages/*")
public class PageServlet extends HttpServlet {
    /**
     * 跳转页面的服务
     *page/cart  跳转到cart.jsp
     *
     */
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String uri = request.getRequestURI();
        int index = uri.lastIndexOf("/");
        //获取最后分路径
        String page = uri.substring(index+1);
        System.out.println(page);

//        if (page.contains(".")){
//            int d = page.lastIndexOf(".");
//            String res = page.substring(d+1,page.length());
//            System.out.println(res);
//            if (res.equals("js")) {
//
//                request.getRequestDispatcher("/WEB-INF/static/js/" + page).forward(request, response);
//            }
//            if (res.equals("css")) {
//
//                request.getRequestDispatcher("/WEB-INF/static/css/" + page).forward(request, response);
//            }
//        }else {
            request.getRequestDispatcher("/WEB-INF/page/" + page + ".jsp").forward(request, response);
//        }

    }
}
